// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

namespace SnapObjects.Data
{
    /// <summary>
    ///     Represents an object used to build the FROM clause of a SQL statement. The From clause specifies the tables, 
    ///     views, derived tables, and joined tables used in the DELETE, SELECT, and UPDATE statements.
    /// </summary>
    public interface ISqlFromBuilder : ISqlJoinBuilder
    {
        /// <summary>
        ///     Adds a table or view (with the alias and the schema specified) to the FROM clause of the current object.
        /// </summary>
        /// <param name="table">The name of the table or view.</param>
        /// <returns>Returns the current ISqlFromBuilder object.</returns>
        ISqlFromBuilder From(string table);

        /// <summary>
        ///     Adds a table or view (with the alias and the schema specified) to the FROM clause of the current object.
        /// </summary>
        /// <param name="table">The name of the table or view.</param>
        /// <param name="alias">The alias of the table or view.</param>
        /// <returns>Returns the current ISqlFromBuilder object.</returns>
        ISqlFromBuilder From(string table, string alias);

        /// <summary>
        ///     Adds a table or view (with the alias and the schema specified) to the FROM clause of the current object.
        /// </summary>
        /// <param name="table">The name of the table or view.</param>
        /// <param name="alias">The alias of the table or view.</param>
        /// <param name="schema">The schema of the table or view.</param>
        /// <returns>Returns the current ISqlFromBuilder object.</returns>
        ISqlFromBuilder From(string table, string alias, string schema);

        /// <summary>
        ///     Adds a table source (table, view, or derived table), specified by a raw SQL, to the FROM clause 
        ///     of the current object, and specifies an alias for this table source.
        /// </summary>
        /// <param name="fromClause">
        ///     A string of raw SQL which is the table source (table, view, or derived table). 
        ///     Actually, you can write any raw SQL if the SQL statement is valid.
        /// </param>
        /// <returns>Returns the current ISqlFromBuilder object.</returns>
        ISqlFromBuilder FromRaw(string fromClause);

        /// <summary>
        ///     Adds a table source (table, view, or derived table), specified by a raw SQL, to the FROM clause 
        ///     of the current object, and specifies an alias for this table source.
        /// </summary>
        /// <param name="fromClause">
        ///     A string of raw SQL which is the table source (table, view, or derived table). 
        ///     Actually, you can write any raw SQL if the SQL statement is valid.
        /// </param>
        /// <param name="builderAlias">he alias for the table source.</param>
        /// <returns>Returns the current ISqlFromBuilder object.</returns>
        ISqlFromBuilder FromRaw(string fromClause, string builderAlias);

        /// <summary>
        ///     Adds a derived table (specified by another ISqlBuilder object and an alias) to the FROM clause of the current object.
        /// </summary>
        /// <param name="sqlBuilder">An ISqlBuilder object which represents a derived table.</param>
        /// <param name="alias">The alias of the derived table.</param>
        /// <returns>Returns the current ISqlFromBuilder object.</returns>
        ISqlFromBuilder From(ISqlBuilder sqlBuilder, string alias);

        /// <summary>
        ///     Gets the alias of a table source that has been added to the current object using the From or FromRaw method.
        /// </summary>
        /// <param name="tableName">The name of a table source that has been added to the current object.</param>
        /// <returns>
        ///     Returns the alias of the specified table source if the table source exists.
        ///     Returns null if the table source does not exist.
        /// </returns>
        string GetTableAlias(string tableName);

        /// <summary>
        ///     Gets whether any table source has been added to the current object using the From or FromRaw method.
        /// </summary>
        bool HasTable { get; }

        /// <summary>
        ///     Returns an ISqlJoinOnAndOr object which represents an object used to build the JOIN clause of a SQL statement.
        /// </summary>
        /// <returns>
        ///     Returns the ISqlJoinOnAndOr object which can be used to build the JOIN clause of a SQL statement 
        ///     (e.g., adding search conditions to the JOIN clause).
        /// </returns>
        ISqlJoinOnAndOr AsJoin();
    }
}
